package com.erp.gather.controller;

import com.erp.gather.domain.bo.ErpCollectProductCategoryQualificationBo;
import com.erp.gather.domain.vo.ErpCollectProductCategoryQualificationVo;
import com.erp.gather.service.IErpCollectProductCategoryQualificationService;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 类目资质信息
 *
 * @author erp
 * @date 2023-10-31
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/gather/collectProductCategoryQualification")
public class ErpCollectProductCategoryQualificationController extends BaseController {

    private final IErpCollectProductCategoryQualificationService iErpCollectProductCategoryQualificationService;

    /**
     * 查询类目资质信息列表
     */
    @GetMapping("/list")
    public TableDataInfo<ErpCollectProductCategoryQualificationVo> list(ErpCollectProductCategoryQualificationBo bo, PageQuery pageQuery) {
        return iErpCollectProductCategoryQualificationService.queryPageList(bo, pageQuery);
    }


    /**
     * 获取类目资质信息详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<ErpCollectProductCategoryQualificationVo> getInfo(@NotNull(message = "主键不能为空")
                                                               @PathVariable Long id) {
        return R.ok(iErpCollectProductCategoryQualificationService.queryById(id));
    }

    /**
     * 新增类目资质信息
     */
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpCollectProductCategoryQualificationBo bo) {
        return toAjax(iErpCollectProductCategoryQualificationService.insertByBo(bo));
    }

    /**
     * 修改类目资质信息
     */
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpCollectProductCategoryQualificationBo bo) {
        return toAjax(iErpCollectProductCategoryQualificationService.updateByBo(bo));
    }

    /**
     * 删除类目资质信息
     *
     * @param ids 主键串
     */
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iErpCollectProductCategoryQualificationService.deleteWithValidByIds(Arrays.asList(ids), true));
    }


    @GetMapping("selectQualificationByCategoryId")
    public R<Object> selectQualificationByCategoryId(Long categoryId) {
        return iErpCollectProductCategoryQualificationService.selectQualificationByCategoryId(categoryId);
    }


}
